{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "dotnet_interactive": {
     "language": "powershell"
    },
    "polyglot_notebook": {
     "kernelName": "powershell"
    }
   },
   "source": [
    "[this doc on github](https://github.com/dotnet/interactive/tree/main/samples/notebooks/polyglot)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "Install-Module -Name Az.ApplicationInsights -RequiredVersion 1.0.3 -Scope CurrentUser "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "Get-PackageProvider"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "Connect-AzAccount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "Set-AzContext -Subscription \"64276bd9-d4bf-4fe3-8b77-36d696e84b26\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "Install-Module -Name Az.Monitor -Scope CurrentUser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "$logs = Get-AzLog -MaxRecord 200 | Select-Object -ExcludeProperty Authorization,Claims,EventTimestamp,HttpRequest,Level,Properties,SubmissionTimestamp\n",
    "$logJson = ConvertTo-Json $logs -Depth 3\n",
    "$logJson | Out-Display -MimeType \"application/json\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "$entryByResourceGroup = [Graph.Histogram]::new()\n",
    "$entryByResourceGroup.name = \"By ResourceGroup\"\n",
    "$entryByResourceGroup.x =  $logs.ResourceGroupName\n",
    "\n",
    "$entryByResourceProvider = [Graph.Histogram]::new()\n",
    "$entryByResourceProvider.name = \"By ResourceProvider\"\n",
    "$entryByResourceProvider.x =  $logs.ResourceProviderName.value\n",
    "\n",
    "$entryByStatus = [Graph.Histogram]::new()\n",
    "$entryByStatus.name = \"By Status\"\n",
    "$entryByStatus.x =  $logs.Status.value\n",
    "\n",
    "\n",
    "New-PlotlyChart -Trace @($entryByResourceGroup,$entryByResourceProvider,$entryByStatus) -Title \"Events\" | Out-Display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "dotnet_interactive": {
     "language": "pwsh"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [],
   "source": [
    "$entryByResourceProviderSuccess = [Graph.Histogram]::new()\n",
    "$entryByResourceProviderSuccess.name = \"Success By ResourceProvider\"\n",
    "$entryByResourceProviderSuccess.x = ($logs | where-object { $_.Status.value -eq \"Succeeded\"}).ResourceProviderName.value\n",
    "\n",
    "$entryByResourceProviderFailure = [Graph.Histogram]::new()\n",
    "$entryByResourceProviderFailure.name = \"Failure By ResourceProvider\"\n",
    "$entryByResourceProviderFailure.x =  ($logs | where-object { $_.Status.value -ne \"Succeeded\"}).ResourceProviderName.value\n",
    "\n",
    "$layout = [Layout]::new()\n",
    "$layout.barmode = \"stack\"\n",
    "New-PlotlyChart -Layout $layout -Trace @($entryByResourceProviderSuccess, $entryByResourceProviderFailure) -Title \"Events outcome by Resource Provider\" | Out-Display"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "file_extension": ".ps1",
   "mimetype": "text/x-powershell",
   "name": "PowerShell",
   "pygments_lexer": "powershell",
   "version": "7.0"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "powershell",
    "items": [
     {
      "aliases": [],
      "languageName": null,
      "name": ".NET"
     },
     {
      "aliases": [
       "C#",
       "c#"
      ],
      "languageName": "C#",
      "name": "csharp"
     },
     {
      "aliases": [
       "F#",
       "f#"
      ],
      "languageName": "F#",
      "name": "fsharp"
     },
     {
      "aliases": [],
      "languageName": "HTML",
      "name": "html"
     },
     {
      "aliases": [
       "js"
      ],
      "languageName": "JavaScript",
      "name": "javascript"
     },
     {
      "aliases": [],
      "languageName": "KQL",
      "name": "kql"
     },
     {
      "aliases": [],
      "languageName": "Mermaid",
      "name": "mermaid"
     },
     {
      "aliases": [],
      "name": "powershell"
     },
     {
      "aliases": [
       "powershell"
      ],
      "languageName": "PowerShell",
      "name": "pwsh"
     },
     {
      "aliases": [],
      "languageName": "SQL",
      "name": "sql"
     },
     {
      "aliases": [],
      "languageName": null,
      "name": "value"
     },
     {
      "aliases": [
       "frontend"
      ],
      "languageName": null,
      "name": "vscode"
     },
     {
      "aliases": [],
      "name": "webview"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
